﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Xml;

namespace WeiboAutomation
{
    public class XML
	{
        static string xmlFile = "Configuration.xml";
        #region xml
        public string read(string node)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlFile);
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("Settings").ChildNodes;
            foreach (XmlNode xn in nodeList)
            {
                XmlNodeList xcn = xn.ChildNodes;
                foreach (XmlNode xcn2 in xcn)
                {
                    if (xcn2.Name == node)
                    {
                        return xcn2.InnerText;
                    }
                }
            }
            return string.Empty;
        }
        public bool write(string node, string value)
        {
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xmlFile);
            XmlNodeList nodeList = xmlDoc.SelectSingleNode("Settings").ChildNodes;
            foreach (XmlNode xn in nodeList)
            {
                foreach (XmlNode xn2 in xn)
                {
                    if (xn2.Name == node)
                    {
                        xn2.InnerText = value;
                        xmlDoc.Save(xmlFile);
                        return true;
                    }
                }
            }
            return false;
        }

        #endregion
	}
}
